<!--
    除了 vue-resource，还可使用 axios 实现数据请求
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
</head>
<body>
    <div id="app">
        <input type="button" value="get请求" @click="getInfo" />
        <input type="button" value="post请求" @click="postInfo" />
        <input type="button" value="jsonp请求" @click="jsonpInfo" />
    </div>

    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                msg: '欢迎学习Vue.js'
            },
            methods:{
                getInfo(){
                    // 发起 get 请求
                    this.$http.get('http://jsonplaceholder.typicode.com/posts')
                    .then(function(res){
                        console.log(res.body);    
                    },function(){
                        console.log('请求失败处理');
                    });
                },
                postInfo(){
                    // post 请求
                    this.$http.post('http://jsonplaceholder.typicode.com/posts', {}, {emulateJSON:true}).then((res)=>{
                        console.log(res.body);
                    }, ()=>{
                        console.log('请求失败处理');
                    });
                },
                jsonpInfo(){
                    // jsonp 请求
                    this.$http.jsonp('http://jsonplaceholder.typicode.com/posts').then((res)=>{
                        console.log(res.body);
                    });
                }
            }
        });
    </script>
</body>
</html>